package com.manong.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.manong.dao.LoginLogMapper;
import com.manong.entity.LoginLog;
import com.manong.service.LoginLogService;
import com.manong.vo.query.LoginLogQueryVo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Dorr
 * @since 2025-03-03
 */
@Transactional
@Service
public class LoginLogServiceImpl extends ServiceImpl<LoginLogMapper, LoginLog> implements LoginLogService {
    @Resource
    private LoginLogMapper loginLogMapper;

    /**
     * 分页查询登录日志
     * @param page
     * @param loginLogQueryVo
     * @return
     */
    @Override
    public IPage<LoginLog> findLoginListByUsername(IPage<LoginLog> page, LoginLogQueryVo loginLogQueryVo) {
        QueryWrapper<LoginLog> queryWrapper = new QueryWrapper<LoginLog>();
        queryWrapper.like(!ObjectUtils.isEmpty(loginLogQueryVo.getUsername()),"username",loginLogQueryVo.getUsername())
                    .orderByDesc("login_time");
        return baseMapper.selectPage(page,queryWrapper);
    }

    /**
     * 批量删除登录日志
     * @param infoIds
     * @return
     */
    @Override
    public boolean delete(List<Long> infoIds) {
        if(baseMapper.deleteLogin(infoIds)>0){
            return true;
        }
        return false;
    }
}
